package jmvcclab.Controller;
import jmvcclab.Model.MainData;
import jmvcclab.Model.OperationValues;

public final class Calc {
    OperationValues OpValues;
    public Calc(MainData m){
        init(m);
    }
    public void init(MainData m){
        m = new MainData();
        m.Result = getAnswer(getResult(m.SortedValues, m.SortedOperations));
    }
    public int getAnswer(int result[]){
        int Answer = 0;
        for(int i = 0; i < result.length; i++){
            Answer+= result[i];
        }
        return Answer;
    }
    public int[] getResult(int SortedValues[],int SortedOperations[]){
        int result[] = null;
        for(int i = 0; i < SortedOperations.length; i++){
            result[i] = getOperationResult(SortedValues[i],SortedValues[i+1],
                    SortedOperations[i]);
        }
        return result;
    }
    private int getOperationResult(int LeftValue, int RightValue, int Operation){
        int result;
        switch (OpValues) {
            case PLUS: result = LeftValue + RightValue;
            case MINUS: result = LeftValue - RightValue;
            case MULT: result = LeftValue * RightValue;
            case UNMULT: result = LeftValue / RightValue;
            default: result = 0;
        }
        return result;
    }
}
